include("shared.lua");
AddCSLuaFile("cl_init.lua");
AddCSLuaFile("shared.lua");
-- Setting up all the different properties of our melon.
ENT.Move = false;
ENT.Delay = 0.05;
ENT.Healthlol = 500;
ENT.FiringRange = 1200;
ENT.NoMoveRange = 50;
ENT.MinRange = 0;
ENT.DeathRadius = 200;
ENT.DeathMagnitude = 65;
ENT.MovingForce = 200;
ENT.MelonModel = "models/props_c17/utilityconnecter006c.mdl";

-- Now we tell the base class to set up the melon. Pay attention - the variables must be defined BEFORE calling Setup().
function ENT:Initialize()
	self:Setup();
	self.Entity:SetMaterial("Straw/StrawTile_diffuse");
	self.jTarget = ents.Create("info_target");
	self.jTarget:SetPos(self.Entity:GetPos());
	self.jTargetName = "johnnylaser" .. self.Entity:EntIndex();
	self.jTarget:SetKeyValue("targetname", self.jTargetName);
	self.jTarget:Spawn();
	self.jTarget:Activate();
	self.Entity:DeleteOnRemove(self.jTarget);
	self.jLaser = ents.Create("env_laser");
	self.jLaser:SetPos(self.Entity:GetPos()+(self.Entity:GetAngles()-Angle(90, 0, 0)):Forward()*26);
	self.jLaser:SetAngles(self.Entity:GetAngles());
	self.jLaser:SetKeyValue("texture", "sprites/bluelaser1.spr");
	self.jLaser:SetKeyValue("texturescroll", 20);
	self.jLaser:SetKeyValue("damage", 0);
	self.jLaser:SetKeyValue("dissolvetype", 1);
	self.jLaser:SetKeyValue("width", 22);
	self.jLaser:SetKeyValue("force", 0);
	self.jLaser:SetKeyValue("LaserTarget", self.jTargetName);
	self.jLaser:SetKeyValue("renderamt", 255);
		if (self.Team == 1) then
		self.jLaser:SetKeyValue("rendercolor", "255 0 0");
		end
		if (self.Team == 2) then
		self.jLaser:SetKeyValue("rendercolor", "0 0 255");
		end
		if (self.Team == 3) then
		self.jLaser:SetKeyValue("rendercolor", "0 255 0");
		end
		if (self.Team == 4) then
		self.jLaser:SetKeyValue("rendercolor", "255 255 0");
		end
		if (self.Team == 5) then
		self.jLaser:SetKeyValue("rendercolor", "255 0 255");
		end
		if (self.Team == 6) then
		self.jLaser:SetKeyValue("rendercolor", "0 255 255");
		end	
	self.jLaser:Spawn();
	self.jLaser:Activate();
	self.jLaser:SetParent(self.Entity);
	self.jLaser:Fire("turnoff", "", 0);
	self.Entity:DeleteOnRemove(self.jLaser);
end
Sound ("Weapon_RPG.Single");


function jStopLaserSound(ent)
	ent:StopSound("Airboat_fan_fullthrottle");
end

--What to do when we've found a target, and we've got the goahead to start attacking
function ENT:Attack ()
	self.Target:TakeDamage(2, self.Entity);
	self.jTarget:SetPos(self.Target:GetPos());
	self.jLaser:Fire("turnon", "", 0);
	self.jLaser:Fire("turnoff", "", 5);
end

--Any other code you want to tag on to the end of the think function.
function ENT:OtherThoughts()
	--self.jLaser:SetPos(self.Entity:GetPos()+self.Entity:GetAngles():Forward()*10);
end

function ENT:OnRemove()
	self.Entity:StopSound("Airboat_fan_fullthrottle");
end